<?php
namespace App\Http\Controllers\Api\Buz;

use App\Http\Controllers\Controller;
use App\Lib\Code;
use App\Repositories\Criteria\AuthUserCriteria;
use App\Repositories\Eloquent\PlatUserBankRepositoryEloquent;
use App\Services\ApiResponseService;
use App\Validators\Buz\RemitBankValidator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RemitController extends Controller
{
    protected $bankRepository;

    public function __construct(PlatUserBankRepositoryEloquent $platUserBankRepositoryEloquent)
    {
        $this->bankRepository = $platUserBankRepositoryEloquent;
        $this->bankRepository->pushCriteria(AuthUserCriteria::class);
    }

    public function update(Request $request, RemitBankValidator $bankValidator)
    {
        $data = $request->all(array_keys($bankValidator->getRules('update')));
        $bankValidator->with($data)->passesOrFail('update');
        $bank = $this->bankRepository->first();
        $bank->update($data);
        return ApiResponseService::success(Code::SUCCESS);
    }
}
